/**  
 * All rights Reserved, Designed By www.flksh.com
 * @date:   2017-11-03 10:27:10   
 * @Copyright: 2013-2017 www.flksh.com Inc. All rights reserved. 
 * 注意：本内容仅限于上海福乐康社区养老服务有限公司内部传阅，禁止外泄以及用于其他的商业目
 */
package com.zx.cloud.service;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zx.cloud.domain.Areas;
import com.zx.cloud.domain.Cities;
import com.zx.cloud.domain.Provinces;
import com.zx.cloud.persistence.AreasMapper;
import com.zx.cloud.persistence.CitiesMapper;
import com.zx.cloud.persistence.CrudMapper;

/**
 * 
 */
@Service
public class ProvincesService extends CrudServiceImpl<Provinces>{
    
    private static final Logger LOGGER = LoggerFactory.getLogger(ProvincesService.class);
    
    @Autowired
    private CitiesMapper citiesMapper;
    
    @Autowired
    private AreasMapper areasMapper;
    
  	@Autowired
    public ProvincesService(CrudMapper<Provinces> mapper) {
        super(mapper);
    }

  	public List<Provinces> findGlobalMsg(){
  		
  		List<Provinces> provinces = super.find(null);
  		
  		if(null != provinces && provinces.size() > 0){
  			
  			for(Provinces province : provinces){
  				
  				String provinceid = province.getProvinceid();
  				
  				List<Cities> cities = citiesMapper.getCities(provinceid);
  				
  				if(null != cities && cities.size() > 0){
  					
  					for(Cities city : cities){
  						
  						String cityid = city.getCityid();
  						
  						List<Areas> areas = areasMapper.getAreas(cityid);
  						city.setAreas(areas);
  					}
  				}
  				province.setCities(cities);
  			}
  		}
  		
  		return provinces;
  	}

}
